package com.company;

public class ElegantStop {
    public static boolean flag = true;
    public static void main(String[] args) throws Exception {
        new Thread(() -> {
            long num = 0;
            while (flag) {
                try {
                    Thread.sleep(50);
                    System.out.println(Thread.currentThread().getName() + " exec times is " + (++num));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "thread 1").start();
        Thread.sleep(200);
        flag = false;
    }
}
